home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1984-04-24 | 1.2 KB | 30 lines |
- 50000 'This is a short version of the Shell sort.
- 50010 'It is designed as a subroutine to be placed into your basic program.
- 50020 'The Shell Sort is an extremely fast Sort when you have a large number
- 50030 'of items to sort. I benchmarked it against a "Bubble Sort" on an array
- 50040 'with 300 items 15 alpha-numeric characters long. The Bubble sort took
- 50050 '25 min. and the Shell sort took 3 min!
- 50060 '
- 50070 '****************** S E T U P ************************************
- 50080 '
- 50090 ' 1. You must DIMension the array A(J) before entering the sub-routine
- 50100 ' 2. "LAST" must be assigned the value of the total number of items to
- 50110 ' be sorted.
- 50120 '
- 50130 '************************* R E S U L T S ***************************
- 50140 '
- 50150 'The Array A(J) will be sorted in ascending order at the end of the Sort.
- 50160 '
- 50170 '****** B A S I C C O D E F O R S H E L L S O R T ********
- 50180 GAP=LAST\2
- 50190 WHILE GAP>0
- 50200 FOR I=GAP+1 TO LAST
- 50210 J=I-GAP
- 50220 WHILE J>0
- 50230 IF A(J)>A(J+GAP) THEN SWAP A(J),A(J+GAP):J=J-GAP ELSE J=0
- 50240 WEND
- 50250 NEXT
- 50260 GAP=GAP\2
- 50270 WEND
- 50280 RETURN ' SORT OF ARRAY A(J) COMPLETED
-